package com.example.spring.bean.load05condition;

import org.springframework.context.annotation.Condition;
import org.springframework.context.annotation.ConditionContext;
import org.springframework.core.env.Environment;
import org.springframework.core.type.AnnotatedTypeMetadata;

/**
 * 实现 Condition
 * <p> 重写 matches(), 定义规则，为true情况下，注册使用Condition的相关 Bean
 * <p>
 */
class WindowCondition implements Condition {

    @Override
    public boolean matches(ConditionContext context, AnnotatedTypeMetadata metadata) {

        //获取当前环境变量(包括我们操作系统是WIN还是LINUX?)
        Environment environment = context.getEnvironment();
        String osName = environment.getProperty("os.name");
        if (osName.contains("Windows")) {
            return true;
        }
        return false;
    }
}
